﻿@{
    ViewBag.Title = "setPrice";
}

@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
    <link href="~/Scripts/miniui/themes/default/medium-mode.css" rel="stylesheet" type="text/css" />      
}


<form id="form1" method="post">
<div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">                
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <a class="mini-button" iconCls="icon-ok" onclick="saveInfo" plain="true">保存</a>
                <span class="separator"></span>
                    <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </tr>
    </table>                
</div>
<div id="layout1" class="mini-layout" style="width:850px;height:420px;"  borderStyle="border:solid 1px #aaa;">

    <div title="代理商" showProxyText="true" region="west" width="350" expanded="true" showSplitIcon="true">
        <div style="margin-left:8px;margin-top:3px;margin-bottom:3px;">
            代理商：<input name="FNumber" class="mini-textbox" style="width:150px;"  onkeypress="setkeyPress()"/>
            <a class="mini-button" iconCls="icon-search" onclick="search" plain="true">查询</a>
        </div>
        <div class="mini-fit">
            <div id="datagrid2" class="mini-datagrid" style="width:100%;height:327px;" 
                idField="FItemID" showFooter="false" allowSortColumn="false" pageSize="10"
                showPager = "true" showPageSize="true" showPageIndex="true" showReloadButton ="false"
                allowCellSelect="true" allowCellEdit="true" onselectionchanged="selectAgent" 
                selectOnLoad="true"fitColumns="false" url="../Corp/GetAgentList">
                <div property="columns">
                    <div type="checkcolumn"></div>      
                    <div type="indexcolumn" width="40" headerAlign="center" >序号</div>        
                    <div field="FNumber" name="FNumber" width="90" headeralign="center" allowsort="true">编码</div>
                    <div field="FName" name="FName" width="180" headeralign="center" allowsort="true">服务商名</div>
                </div>   
            </div>
        </div>
    </div>

    <div title="center" region="center" width="100%">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:380px;" idField="FItemID" 
            allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true"
            borderStyle="border:0;" url="../Corp/GetAgentPrice" fitColumns="false"  
            sortMode="client" onlyCheckSelection ="true" showPager="false">
                <div property="columns">    
                <div field="FName" width="90" allowSort="true" headerAlign="center" >软件模块</div> 
                <div field="FAgentPrice" width="80" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">代理价(年)
                     <input property="editor" class="mini-spinner PopInput" minValue="0" maxValue="99999999" value="0" style="width:100%;"/>
                </div>                                        
                <div field="FSalesPrice" width="80" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">零售价(年)
                     <input property="editor" class="mini-spinner PopInput" minValue="0" maxValue="99999999" value="0" style="width:100%;"/>
                </div>   
                <div field="FAgentAllPrice" width="110" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">代理价(无限期)
                    <input property="editor" class="mini-spinner PopInput" minValue="0" maxValue="99999999" value="0" style="width:100%;" />
                </div>
                <div field="FAllPrice" width="110" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">零售价(无限期)
                     <input property="editor" class="mini-spinner PopInput" minValue="0" maxValue="99999999" value="0" style="width:100%;"/>
                </div>   
            </div>
        </div>  
    </div>

</div>
</form>
<script>
    mini.parse();

    function FormShown() {
        LoadAgentList();
    }

    function SetInfoData(data) {
    }

    function LoadAgentList() {
        var json = "[{";
        json = json + "'search':'" + mini.getbyName("FNumber").getValue() + "'";
        json = json + "}]";
        var grid = mini.get("datagrid2");
        grid.load({ mjson: json });
    }
    function search() {
        LoadAgentList();
    }
    function setkeyPress() {
        if (event.keyCode == 13)
            LoadAgentList();
    }

    function LoadPriceList() {
        var grid2 = mini.get("datagrid2");
        var row = grid2.getSelected();
        if (row) {
            var json = "[{";
            json = json + "'FSystemAppID':'" + parent.window.getSystemAppID() +"',";
            json = json + "'FCorpClassID':'" + row.FItemID + "'";
            json = json + "}]";
            var grid = mini.get("datagrid1");
            grid.load({ mjson: json });
        }
    }

    function onComboxChanged() {
        LoadPriceList();
    }

    function saveInfo() {
        var grid2 = mini.get("datagrid2");
        var row = grid2.getSelected();
        if (row) {
            var data = mini.get("datagrid1").getData();
            var jsondata = mini.encode(data);
            var json = '[{"data":' + jsondata + ',"FSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
            $.post("SaveAgentPrice", { mjson: json }, function (data) {
                var ret = mini.decode(data);
                if (ret.status == 1) {
                    mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 }, function () {
                        mini.alert("保存完成");
                    });
                    NewInfo();
                    if (mini.getbyName("ck1").getChecked() == false)
                        CloseWindow();
                }
                else {
                    mini.alert("异常：" + ret.error);
                }
            });
        }
    }

    function selectAgent(e) {
        var grid2 = e.sender;
        var record = grid2.getSelected();
        var json = '[{"FCorpClassID":'+record.FItemID+',"FSystemAppID":"'+parent.window.getSystemAppID()+'"}]';
        var grid = mini.get("datagrid1");
        grid.load({ mjson: json });
    }
</script>